package org.jgs1904.practice;

/**
 * @author: 默苍璃
 * @date: 2022-09-06 17:49
 * <p>
 * 求解 一元二次方程ax^2+bx+c=0
 * <p>
 * 求根公式
 * (-b(+-)根号(b2-4ac))/2a
 */
public class OneAndTwo {

    public static void main(String[] args) {
        // x*x + 3*x - 4 = 0
        double a = 1.0;
        double b = 3.0;
        double c = -4.0;
        // 求平方根可用 Math.sqrt():
        // double x = Math.sqrt(2)); // ==> 1.414
        // TODO:
        double r1 = 0;
        double r2 = 0;

        final double sqrt = Math.sqrt(b * b - 4 * a * c);

        r1 = (-b + sqrt) / (2 * a);
        r2 = (-b - sqrt) / (2 * a);

        System.out.println(r1 + ", " + r2);
        System.out.println(r1 == 1 && r2 == -4 ? "测试通过" : "测试失败");
    }

}
